<?php
global $_GPC, $_W;
$GLOBALS['frames'] = $this->getMainMenu2();

$where=" where uniacid=:uniacid and city_id=:city_id";
$data[':uniacid']=$_W['uniacid']; 
$data[':city_id']= $_COOKIE['account_id'];

if(isset($_GPC['keywords'])){
    $where.=" and title LIKE  concat('%', :name,'%') ";
    $data[':name']=$_GPC['keywords']; 
}
if(!empty($_GPC['time'])){
   $start=strtotime($_GPC['time']['start']);
   $end=strtotime($_GPC['time']['end']);
  $where.=" and UNIX_TIMESTAMP(time) >={$start} and UNIX_TIMESTAMP(time)<={$end}";
}

$pageindex = max(1, intval($_GPC['page']));
$pagesize=10;
$sql="select * from".tablename('zhtc_video_card') ."".$where." ORDER BY id DESC";
$total=pdo_fetchcolumn("select count(*) from".tablename('zhtc_video_card')."".$where,$data);
$select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
$list=pdo_fetchall($select_sql,$data);
foreach ($list as $key => $value) {
  $list[$key]['onnum'] = pdo_fetchcolumn("select count(*) from ims_zhtc_video_card_data where cid = ".$value['id']." and state = 1");
  $list[$key]['leftnum'] = pdo_fetchcolumn("select count(*) from ims_zhtc_video_card_data where cid = ".$value['id']." and state = 0");
}

$pager = pagination($total, $pageindex, $pagesize);
if($_GPC['op']=='delete'){
    $res=pdo_delete('zhtc_video_card',array('id'=>$_GPC['id']));
    pdo_delete('zhtc_video_card_data',array('cid'=>$_GPC['id']));
    if($res){
      message('删除成功！', $this->createWebUrl('videocardlist'), 'success');
    }else{
      message('删除失败！','','error');
    }
}
include $this->template('web/videocardlist');